import { http } from "@/utils/http";

// 用户接口类型定义
export interface UserQueryParams {
  id?: number;
  page?: number;
  per_page?: number;
  department?: string; // 按部门过滤
}

export interface UserCreateParams {
  name: string;
  phone?: string;
  department?: string;
  position?: string;
  email: string;
  roles?: string;
  description?: string;
  oa_user?: string;
  password: string;
}

export interface UserUpdateParams {
  id: number;
  name?: string;
  phone?: string;
  department?: string;
  position?: string;
  email?: string;
  roles?: string;
  description?: string;
  oa_user?: string;
  password?: string;
}

export interface UserDeleteParams {
  id: number;
}

export interface UserInfo {
  id: number;
  name: string;
  phone: string;
  department: string;
  position: string;
  email: string;
  roles: string;
  description: string;
  oa_user: string;
}

export interface UserQueryResult {
  code: number;
  message: string;
  data: UserInfo | UserInfo[];
  pagination?: {
    page: number;
    per_page: number;
    total: number;
    pages: number;
  };
}

export interface UserOperationResult {
  code: number;
  message: string;
  data?: UserInfo;
}

/** 查询用户 - 支持单个用户查询和分页查询 */
export const queryUser = (params?: UserQueryParams) => {
  return http.request<UserQueryResult>("post", "/api/user/query", {
    data: params
  });
};

/** 创建用户 */
export const createUser = (data: UserCreateParams) => {
  return http.request<UserOperationResult>("post", "/api/user/create", {
    data
  });
};

/** 更新用户 */
export const updateUser = (data: UserUpdateParams) => {
  return http.request<UserOperationResult>("post", "/api/user/update", {
    data
  });
};

/** 删除用户 */
export const deleteUser = (data: UserDeleteParams) => {
  return http.request<UserOperationResult>("post", "/api/user/delete", {
    data
  });
};
